<?php

namespace app\controllers\api;

use app\controllers\Uploader;
use Yii;
use yii\helpers\Json;

class SundryController extends BaseController {
    public function actions() {
        return [
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    public function actionUpload($callback = '') {
        // 上传配置
        $config = array(
            // 存储文件夹
            "savePath" => "web/upload/",
            // 允许的文件最大尺寸，单位KB
            "maxSize" => 1000,
            // 允许的文件格式
            "allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" )
        );
        $up = new Uploader( "upfile" , $config );

        $info = $up->getFileInfo();
        if($callback) {
            return '<script>'.$callback.'('.json_encode($info).')</script>';
        } else {
            return Json::encode($info);
        }
    }
}
